use thiserror::Error;

#[derive(Error, Debug, PartialEq)]
#[non_exhaustive]
pub enum Error {
    // #[error("IO error: {0}")]
    // IO(#[from] std::io::Error),

    #[error("Serial connect failed")]
    SerialConnectFailed,

    #[error("Session key error")]
    SessionKeyError,

    #[error("Session create deny")]
    SessionCreateDeny,

    #[error("Failed to connect to the broker")]
    ConnectionFailed,

    #[error("Timeout while running command")]
    Timeout,

    #[error("Invalid response header")]
    RespError,

    #[error("Sub topic failed")]
    TopicSubError,

    #[error("Pub topic failed")]
    TopicPubError,

    #[error("Packet too large")]
    OverSizedPacket,

    #[error("Packet invalid")]
    InvalidPacket,

    #[error("Checksum not match")]
    ChecksumMismatch,

    #[error("Header length {0:#x} not equal with payload length {0:#x}")]
    PayloadLenMismatch(u16, u16),

    #[error("Invalid cmd id {0:#x}")]
    CmdIDMismatch(u8),

    #[error("Invalid device version")]
    InvalidDevVer,

    #[error("Not support the struct parse")]
    TypeNotSupport,

    #[error("The type of struct is not support")]
    TypeMismatch,

    #[error("The VIN num `{0}` is invalid")]
    InvalidVIN(String),

    #[error("Send data to mpsc channel failed, `{0}`")]
    SenderError(String),
}